package spring3.controller;

import java.rmi.RemoteException;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import spring3.form.Administrador;
import webservice.ServicioAplicadoStub;
import webservice.ServicioAplicadoStub.AdministradorVO;
import webservice.ServicioAplicadoStub.AgregarAdministrador;
import webservice.ServicioAplicadoStub.AgregarAdministradorResponse;

 


// TODO: Auto-generated Javadoc
/**
 * The Class CuentaController.
 */

public class CuentaController {
 
	@RequestMapping("/registroAdmin")
	public ModelAndView registroAdministrador(@ModelAttribute("Administrador") @Valid  Administrador admin, BindingResult result) {
		try {
			if(admin.getUsername() == "" || admin.getPassword() == ""){
				return new ModelAndView("error","message", "campos vacios");
			}

			ServicioAplicadoStub servicioInvocado = new ServicioAplicadoStub();
			AdministradorVO adminVO = new AdministradorVO();
			adminVO.setUsername(admin.getUsername());
			adminVO.setPassword(admin.getPassword());
			AgregarAdministrador registroAdminSTUB = new AgregarAdministrador();
			
			registroAdminSTUB.setOAdministradorVO(adminVO);
			AgregarAdministradorResponse registroAdminSTUBResponse = servicioInvocado.agregarAdministrador(registroAdminSTUB);
			String mensaje = registroAdminSTUBResponse.get_return();
			return new ModelAndView("saludo", "message", mensaje);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new ModelAndView("error", "message", "ERROR");
		}
	}

	@RequestMapping("/menu")
	public ModelAndView modificarClienteAction() {

		return new ModelAndView("menu","command", new Administrador());
	
		

	}

	/**
	 * Abrir principal.
	 *
	 * @return the model and view
	 */
	@RequestMapping("/Principal")
	public ModelAndView abrirPrincipal() {
		return new ModelAndView("administracion", "command", new Administrador());
	}

	/**
	 * Logear.
	 *
	 * @param admin the admin
	 * @param result the result
	 * @param session the session
	 * @return the model and view
	 */
	@RequestMapping("/logear")
	public ModelAndView logear(@ModelAttribute("Administrador") @Valid Administrador admin, BindingResult result, HttpSession session) {


		
		
			return new ModelAndView("MenuLogeado");

	}

	/**
	 * Mostrar clientes.
	 *
	 * @param session the session
	 * @return the model and view
	 */
	@RequestMapping("/mostrarClientes")
	public ModelAndView mostrarClientes(HttpSession session) {
		
				return new ModelAndView("MostrarClientes");
			
	}

	

	



	/**
	 * Registro clientes.
	 *
	 * @param cliente the cliente
	 * @param result the result
	 * @return the model and view
	 */
	@RequestMapping("/registroClientes")
	public ModelAndView registroClientes( BindingResult result) {
		return new ModelAndView("Cliente");
	}


	
     
	

}